package com.iis.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Calendar;

import com.iis.databaseutil.DatabaseConnection;
import com.iis.entity.InsuranceTransaction;
import com.iis.entity.Salesman;
import com.iis.entity.Person;

public class TransactionDAO {
private static final TransactionDAO transactionDAO = new TransactionDAO();
	
	private TransactionDAO(){
		
	}
	
	public static TransactionDAO getInstances(){
		return transactionDAO;
	}
	
	Connection koneksiKu = null;
	PreparedStatement psSelectAllTransaction = null;
	//String sqlGetAllTransaction = "Select * FROM insurance_transaction trx, person p where s.person_idPerson = p.idPerson and s.deleted = 'N' and p.deleted = 'N'";
	String sqlGetAllTransaction = "";
	
	public ArrayList<InsuranceTransaction> getAll(){
		koneksiKu = DatabaseConnection.getDataConnection();
		int index = 1;
		ArrayList<InsuranceTransaction> arrTransaction = new ArrayList<InsuranceTransaction>();
		try {

			psSelectAllTransaction = koneksiKu.prepareStatement(sqlGetAllTransaction);
			ResultSet rs = psSelectAllTransaction.executeQuery();

			while (rs.next()) {
				long idSalesman = rs.getLong("idSalesman");
				String empNo = rs.getString("Employee_No");
				double targetSales = rs.getDouble("Sales_Target");
				long idPerson = rs.getLong("idPerson");
				String name = rs.getString("Name");
				String address = rs.getString("Address");
				
				/*InsuranceTransaction salesman = new Salesman();
				salesman.setSalesmanID(idSalesman);
				salesman.setEmployeeNo(empNo);;
				salesman.setSalesTarget(targetSales);
				salesman.setPersonID(idPerson);
				salesman.setName(name);
				salesman.setAddress(address);

				arrTransaction.add(salesman);*/

			}

		} catch (SQLException e) {
			e.printStackTrace();
		}

		return arrTransaction;
	}
}
